import { defineStore } from 'pinia'

export const useDatesReports = defineStore('datesReport', () => {
  
  const datesList = ref([
    {
      ID: 0,
      NMONTH: 'Выбрать период',
    DN_PL: '2022-05-26T00:00:00',
      DK_PL: '2022-06-25T00:00:00',
      DN_LG: '2022-05-21T00:00:00',
      DK_LG: '2022-06-20T00:00:00',
      YEARS: 2022,
      MONTHS: 6,
    disabled: true,
    }
  ])

  const selectPeriod = ref(
    {
    ID: 0,
      NMONTH: 'Выбрать период',
    DN_PL: '2022-05-26T00:00:00',
      DK_PL: '2022-06-25T00:00:00',
      DN_LG: '2022-05-21T00:00:00',
      DK_LG: '2022-06-20T00:00:00',
      YEARS: 2022,
      MONTHS: 6,
    disabled: true,
  })

  function setList(list) {
    datesList.value.push(...list)
  }

  function resetSelectPeriod() {
	selectPeriod.value = {
	ID: 0,
    NMONTH: 'Выбрать период',
	DN_PL: '2022-05-26T00:00:00',
    DK_PL: '2022-06-25T00:00:00',
    DN_LG: '2022-05-21T00:00:00',
    DK_LG: '2022-06-20T00:00:00',
    YEARS: 2022,
    MONTHS: 6,
	disabled: true,
  }
  }
  function setSelectedPeriodById(idPeriod){
     selectPeriod.value = datesList.value.find((element) => element.ID == idPeriod);
  }

  function setSelectedPeriod(dictDate) {
	selectPeriod.value = dictDate
  }

  return { datesList, selectPeriod, setList, resetSelectPeriod, setSelectedPeriod, setSelectedPeriodById }

})